using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Syncfusion.Windows.Forms.Chart;
using Syncfusion.Windows.Forms;

namespace SIM_TPN3a
{ 
    public partial class Form1 : Office2007Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            lstResultado.Items.Clear();
            GenVarAle gva = new GenVarAle();
            switch (cboDistribucion.SelectedIndex)
            {   //exp, poi, normal
                case 0:
                    { 
                         for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
                        {
                            lstResultado.Items.Add(gva.DistExponencial(Convert.ToDouble(txtLambda.Text)));
                            //Thread.Sleep(10);
                        }
                        break;
                    }
                case 1:
                    {
                        for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
                        {
                            lstResultado.Items.Add(gva.DistPoisson(Convert.ToDouble(txtLambda.Text)));
                            //Thread.Sleep(10);
                        }
                        break;
                    }
                case 2:
                    {
                        for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)
                        {
                            lstResultado.Items.Add(gva.DistNormal(Convert.ToDouble(txtMedia.Text),Convert.ToDouble(txtDesviacion.Text)));
                            //Thread.Sleep(10);
                        }
                        break;
                    }
              }

              btnGenerarGrafico.Enabled = true;

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void cboDistribucion_SelectionChangeCommitted(object sender, EventArgs e)
        {
            switch (cboDistribucion.SelectedIndex)
            {   //exp, poi, normal
                case 0:
                    {
                        txtMedia.Enabled = false;
                        txtDesviacion.Enabled = false;
                        txtLambda.Enabled = true;
                        break;
                    }
                case 1:
                    {
                        txtMedia.Enabled = false;
                        txtDesviacion.Enabled = false;
                        txtLambda.Enabled = true;
                        break;
                    }
                case 2:
                    {
                        txtMedia.Enabled = true;
                        txtDesviacion.Enabled = true;
                        txtLambda.Enabled = false;
                        break;
                    }
               
            }
        }

        private void btnGenerarGrafico_Click(object sender, EventArgs e)
        {
            chartControl1.Series.Clear();

            cargarGrafico();
        }
        private void cargarGrafico()
        {
            Random r = new Random();

            ChartSeries Histogram = new ChartSeries(cboDistribucion.Text, ChartSeriesType.Histogram);

            //cargo puntos a la serie , cargo la x la y no me importa

                for (int j = 0; j < lstResultado.Items.Count-1; j++)
                {
                    Histogram.Points.Add(Convert.ToDouble(lstResultado.Items[j].ToString()), 1);
                }

            Histogram.Text = Histogram.Name;

            //cantidad de intervalos

            Histogram.ConfigItems.HistogramItem.NumberOfIntervals = Convert.ToInt32(Math.Floor(Math.Sqrt(Convert.ToDouble(textBox1.Text))));
            
            // amplitud de intervalos

            chartControl1.Series.Add(Histogram);
            Syncfusion.Windows.Forms.Chart.ChartAxis miChartAxis = new ChartAxis();
            miChartAxis.RangeType = ChartAxisRangeType.Auto;
            //MinMaxInfo mirango = new MinMaxInfo(0, 1, (1 / double.Parse(Histogram.ConfigItems.HistogramItem.NumberOfIntervals.ToString())));
            //Histogram.XAxis.SetRange(mirango);

            chartControl1.DropSeriesPoints = true;

            // Set the title
            chartControl1.Text = cboDistribucion.Text + "  \r\n\n" + "n= " + textBox1.Text;
            chartControl1.Visible = true;
        }
        
    }
}